#ifndef ParallelMPI_H
#define ParallelMPI_H

#include <string>
#include <vector>
#include <omp.h>

#include <mpi.h>


class ParallelMPI {

public:

    ParallelMPI(int* argc, char*** argv);

    virtual ~ParallelMPI();

    void init();
    void finish();

    inline bool is_master() 
    {
        return (pic_rk==0);
    }

    inline void barrier() 
    {
        MPI_Barrier( PMPI_COMM_WORLD );
    }

    inline int get_rank() 
    {
        return pic_rk;
    }

    inline int get_size() 
    {
        return pic_sz;
    }
    
    void reduce_sum_double(double* src, double* des, int n);
    void all_reduce_sum_double(double* src, double* des, int n);

    void reduce_sum_int(int* src, int* des, int n);
    void all_reduce_sum_int(int* src, int* des, int n);

    void gatherv_double(double* src, int sendcount, double* des, int* recvcounts, int* displs, int root);
    void gatherv_int(int* src, int sendcount, int* des, int* recvcounts, int* displs, int root);


    int pic_sz;

    int pic_rk;


protected:

    MPI_Comm PMPI_COMM_WORLD;
};

#endif
